home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / JFC.bin / JScrollBar.java < prev    next >
Text File  |  1998-06-30  |  24KB  |  793 lines

  1. /*
  2.  * @(#)JScrollBar.java    1.46 98/03/09
  3.  * 
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  */
  20.  
  21. package com.sun.java.swing;
  22.  
  23. import java.io.Serializable;
  24. import java.awt.Component;
  25. import java.awt.Adjustable;
  26. import java.awt.Dimension;
  27. import java.awt.event.AdjustmentListener;
  28. import java.awt.event.AdjustmentEvent;
  29. import java.awt.Graphics;
  30.  
  31. import com.sun.java.swing.event.*;
  32. import com.sun.java.swing.plaf.*;
  33. import com.sun.java.accessibility.*;
  34.  
  35.  
  36. /**
  37.  * An implementation of a scrollbar. The user positions the knob in the
  38.  * scrollbar to determine the contents of the viewing area. The
  39.  * program typically adjusts the display so that the end of the
  40.  * scrollbar represents the end of the displayable contents, or 100%
  41.  * of the contents. The start of the scrollbar is the beginning of the 
  42.  * displayable contents, or 0%. The postion of the knob within
  43.  * those bounds then translates to the corresponding percentage of
  44.  * the displayable contents.
  45.  * <p>
  46.  * Typically, as the position of the knob in the scrollbar changes
  47.  * a corresponding change is made to the position of the JViewPort on
  48.  * the underlying view, changing the contents of the JViewPort.
  49.  * <p>
  50.  * Warning: serialized objects of this class will not be compatible with
  51.  * future swing releases.  The current serialization support is appropriate
  52.  * for short term storage or RMI between Swing1.0 applications.  It will
  53.  * not be possible to load serialized Swing1.0 objects with future releases
  54.  * of Swing.  The JDK1.2 release of Swing will be the compatibility
  55.  * baseline for the serialized form of Swing objects.
  56.  *
  57.  * @see JScrollPane
  58.  * @beaninfo
  59.  *      attribute: isContainer false
  60.  *    description: A component that helps determine the visible content range of an area.
  61.  *
  62.  * @version 1.46 03/09/98
  63.  * @author David Kloba
  64.  */
  65. public class JScrollBar extends JComponent implements Adjustable, Accessible
  66. {
  67.     /**
  68.      * All changes from the model are treated as though the user moved
  69.      * the scrollbar knob.  
  70.      */
  71.     private ChangeListener fwdAdjustmentEvents = new ModelListener();
  72.  
  73.  
  74.     /**
  75.      * The model that represents the scrollbar's minimum, maximum, extent
  76.      * (aka "visibleAmount") and current value.
  77.      * @see #setModel
  78.      */
  79.     protected BoundedRangeModel model;
  80.  
  81.  
  82.     /**
  83.      * @see #setOrientation
  84.      */
  85.     protected int orientation;
  86.  
  87.  
  88.     /**
  89.      * @see #setUnitIncrement
  90.      */
  91.     protected int unitIncrement;
  92.  
  93.  
  94.     /**
  95.      * @see #setBlockIncrement
  96.      */
  97.     protected int blockIncrement;
  98.  
  99.     
  100.     private void checkOrientation(int orientation) {
  101.         switch (orientation) {
  102.         case VERTICAL:
  103.         case HORIZONTAL:
  104.             break;
  105.         default:
  106.             throw new IllegalArgumentException("orientation must be one of: VERTICAL, HORIZONTAL");
  107.         }
  108.     }
  109.  
  110.  
  111.     /**
  112.      * Creates a scrollbar with the specified orientation,
  113.      * value, extent, mimimum, and maximum.
  114.      * The "extent" is the size of the viewable area. It is also known
  115.      * as the "visible amount". 
  116.      * <p>
  117.      * Note: Use <code>setBlockIncrement</code> to set the block 
  118.      * increment to a size slightly smaller than the view's extent.
  119.      * That way, when the user jumps the knob to an adjacent position,
  120.      * one or two lines of the original contents remain in view.
  121.      * 
  122.      * @exception IllegalArgumentException if orientation is not one of VERTICAL, HORIZONTAL
  123.      * 
  124.      * @see #setOrientation
  125.      * @see #setValue
  126.      * @see #setVisibleAmount
  127.      * @see #setMinimum
  128.      * @see #setMaximum
  129.      */
  130.     public JScrollBar(int orientation, int value, int extent, int min, int max)   
  131.     {
  132.         checkOrientation(orientation);
  133.         this.unitIncrement = 1;
  134.         this.blockIncrement = (extent == 0) ? 1 : extent;
  135.         this.orientation = orientation;
  136.         this.model = new DefaultBoundedRangeModel(value, extent, min, max);
  137.         this.model.addChangeListener(fwdAdjustmentEvents);
  138.         updateUI();
  139.     }
  140.  
  141.  
  142.     /**
  143.      * Creates a scrollbar with the specified orientation
  144.      * and the following initial values:
  145.      * <pre>
  146.      * minimum = 0 
  147.      * maximum = 100 
  148.      * value = 0
  149.      * extent = 10
  150.      * </pre>
  151.      */
  152.     public JScrollBar(int orientation) {
  153.         this(orientation, 0, 10, 0, 100);
  154.     }
  155.  
  156.  
  157.     /**
  158.      * Creates a vertical scrollbar with the following initial values:
  159.      * <pre>
  160.      * minimum = 0 
  161.      * maximum = 100 
  162.      * value = 0
  163.      * extent = 10
  164.      * </pre>
  165.      */
  166.     public JScrollBar() {
  167.         this(VERTICAL);
  168.     }
  169.  
  170.  
  171.     /**
  172.      * Returns the delegate that implements the look and feel for 
  173.      * this component.
  174.      *
  175.      * @see JComponent#setUI
  176.      */
  177.     public ScrollBarUI getUI() { 
  178.         return (ScrollBarUI)ui;
  179.     }
  180.  
  181.  
  182.     /**
  183.      * @see JComponent#updateUI
  184.      */
  185.     public void updateUI() {
  186.         setUI((ScrollBarUI)UIManager.getUI(this));
  187.     }
  188.  
  189.  
  190.     /**
  191.      * Returns the name of the LookAndFeel class for this component.
  192.      *
  193.      * @return "ScrollBarUI"
  194.      * @see JComponent#getUIClassID
  195.      * @see UIDefaults#getUI
  196.      */
  197.     public String getUIClassID() {
  198.         return "ScrollBarUI";
  199.     }
  200.  
  201.  
  202.  
  203.     /**
  204.      * Returns the component's orientation (horizontal or vertical). 
  205.      *                     
  206.      * @return VERTICAL or HORIZONTAL
  207.      * @see #setOrientation
  208.      * @see java.awt.Adjustable#getOrientation
  209.      */
  210.     public int getOrientation() { 
  211.         return orientation; 
  212.     }
  213.  
  214.  
  215.     /**
  216.      * Set the scrollbar's orientation to either VERTICAL or
  217.      * HORIZONTAL.
  218.      * 
  219.      * @exception IllegalArgumentException if orientation is not one of VERTICAL, HORIZONTAL
  220.      * @see #getOrientation
  221.      * @beaninfo
  222.      *   preferred: true
  223.      *       bound: true
  224.      * description: The scrollbar's orientation.
  225.      *        enum: VERTICAL JScrollBar.VERTICAL 
  226.      *              HORIZONTAL JScrollBar.HORIZONTAL
  227.      */
  228.     public void setOrientation(int orientation) 
  229.     { 
  230.         checkOrientation(orientation);
  231.         int oldValue = orientation;
  232.         this.orientation = orientation;
  233.         firePropertyChange("orientation", oldValue, orientation);
  234.  
  235.         if ((oldValue != orientation) && (accessibleContext != null)) {
  236.             accessibleContext.firePropertyChange(
  237.                     AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
  238.                     ((oldValue == VERTICAL) 
  239.                      ? AccessibleState.VERTICAL : AccessibleState.HORIZONTAL),
  240.                     ((orientation == VERTICAL) 
  241.                      ? AccessibleState.VERTICAL : AccessibleState.HORIZONTAL));
  242.         }
  243.     }
  244.  
  245.  
  246.     /**
  247.      * Returns data model that handles the scrollbar's four
  248.      * fundamental properties: minimum, maximum, value, extent.
  249.      * 
  250.      * @see #setModel
  251.      */
  252.     public BoundedRangeModel getModel() { 
  253.         return model; 
  254.     }
  255.  
  256.  
  257.     /**
  258.      * Sets the model that handles the scrollbar's four
  259.      * fundamental properties: minimum, maximum, value, extent.
  260.      * 
  261.      * @see #getModel
  262.      * @beaninfo
  263.      *       bound: true
  264.      *       expert: true
  265.      * description: The scrollbar's BoundedRangeModel.
  266.      */
  267.     public void setModel(BoundedRangeModel newModel) {
  268.         Integer oldValue = null;
  269.         BoundedRangeModel oldModel = model;
  270.         if (model != null) {
  271.             model.removeChangeListener(fwdAdjustmentEvents);
  272.             oldValue = new Integer(model.getValue());
  273.         }
  274.         model = newModel;
  275.         if (model != null) {
  276.             model.addChangeListener(fwdAdjustmentEvents);
  277.         }
  278.  
  279.         firePropertyChange("model", oldModel, model);
  280.  
  281.         if (accessibleContext != null) {
  282.             accessibleContext.firePropertyChange(
  283.                     AccessibleContext.ACCESSIBLE_VALUE_PROPERTY,
  284.                     oldValue, new Integer(model.getValue()));        
  285.         }
  286.     }
  287.  
  288.  
  289.     /**
  290.      * Returns the amount to change the scrollbar's value by,
  291.      * given a unit up/down request.  A ScrollBarUI implementation
  292.      * typically calls this method when the user clicks on a scrollbar 
  293.      * up/down arrow and uses the result to update the scrollbar's
  294.      * value.   Subclasses my override this method to compute
  295.      * a value, e.g. the change required to scroll up or down one
  296.      * (variable height) line text or one row in a table.
  297.      * <p>
  298.      * The JScrollPane component creates scrollbars (by default) 
  299.      * that override this method and delegate to the viewports
  300.      * Scrollable view, if it has one.  The Scrollable interface
  301.      * provides a more specialized version of this method.
  302.      * 
  303.      * @param direction is -1 or 1 for up/down respectively
  304.      * @return the value of the unitIncrement property
  305.      * @see #setUnitIncrement
  306.      * @see #setValue
  307.      * @see Scrollable#getScrollableUnitIncrement
  308.      */
  309.     public int getUnitIncrement(int direction) { 
  310.         return unitIncrement; 
  311.     }
  312.  
  313.  
  314.     /**
  315.      * Sets the unitIncrement property.
  316.      * @see #getUnitIncrement
  317.      * @beaninfo
  318.      *   preferred: true
  319.      *       bound: true
  320.      * description: The scrollbar's unit increment.
  321.      */
  322.     public void setUnitIncrement(int unitIncrement) { 
  323.         int oldValue = this.unitIncrement;
  324.         this.unitIncrement = unitIncrement;
  325.         firePropertyChange("unitIncrement", oldValue, unitIncrement);
  326.     }
  327.  
  328.  
  329.     /**
  330.      * Returns the amount to change the scrollbar's value by,
  331.      * given a block (usually "page") up/down request.  A ScrollBarUI 
  332.      * implementation typically calls this method when the user clicks 
  333.      * above or below the scrollbar "knob" to change the value
  334.      * up or down by large amount.  Subclasses my override this 
  335.      * method to compute a value, e.g. the change required to scroll 
  336.      * up or down one paragraph in a text document.
  337.      * <p>
  338.      * The JScrollPane component creates scrollbars (by default) 
  339.      * that override this method and delegate to the viewports
  340.      * Scrollable view, if it has one.  The Scrollable interface
  341.      * provides a more specialized version of this method.
  342.      * 
  343.      * @param direction is -1 or 1 for up/down respectively
  344.      * @return the value of the blockIncrement property
  345.      * @see #setBlockIncrement
  346.      * @see #setValue
  347.      * @see Scrollable#getScrollableBlockIncrement
  348.      */
  349.     public int getBlockIncrement(int direction) { 
  350.         return blockIncrement; 
  351.     }
  352.  
  353.  
  354.     /**
  355.      * Sets the blockIncrement property.
  356.      * @see #setBlockIncrement()
  357.      * @beaninfo
  358.      *   preferred: true
  359.      *       bound: true
  360.      * description: The scrollbar's block increment.
  361.      */
  362.     public void setBlockIncrement(int blockIncrement) { 
  363.         int oldValue = this.blockIncrement;
  364.         this.blockIncrement = blockIncrement;
  365.         firePropertyChange("blockIncrement", oldValue, blockIncrement);
  366.     }
  367.  
  368.  
  369.     /**
  370.      * For backwards compatibility with java.awt.Scrollbar.
  371.      * @see Adjustable#getUnitIncrement
  372.      * @see #getUnitIncrement(int)
  373.      */
  374.     public int getUnitIncrement() {
  375.         return unitIncrement;
  376.     }
  377.  
  378.  
  379.     /**
  380.      * For backwards compatibility with java.awt.Scrollbar.
  381.      * @see Adjustable#getBlockIncrement
  382.      * @see #getBlockIncrement(int)
  383.      */
  384.     public int getBlockIncrement() {
  385.         return blockIncrement;
  386.     }
  387.  
  388.  
  389.     /**
  390.      * Returns the scrollbar's value.
  391.      * @return the model's value property
  392.      * @see #setValue
  393.      */
  394.     public int getValue() { 
  395.         return getModel().getValue(); 
  396.     }
  397.  
  398.  
  399.     /**
  400.      * Sets the scrollbar's value.  This method just forwards the value
  401.      * to the model.
  402.      *
  403.      * @see #getValue
  404.      * @see BoundedRangeModel#setValue
  405.      * @beaninfo
  406.      *   preferred: true
  407.      *       bound: true
  408.      * description: The scrollbar's current value.
  409.      */
  410.     public void setValue(int value) {
  411.         BoundedRangeModel m = getModel();
  412.         int oldValue = m.getValue();
  413.         m.setValue(value);
  414.  
  415.         if (accessibleContext != null) {
  416.             accessibleContext.firePropertyChange(
  417.                     AccessibleContext.ACCESSIBLE_VALUE_PROPERTY,
  418.                     new Integer(oldValue),
  419.                     new Integer(m.getValue()));
  420.         }
  421.     }
  422.  
  423.  
  424.     /**
  425.      * Returns the scrollbar's extent, aka its "visibleAmount".  In many 
  426.      * scrollbar look and feel implementations the size of the 
  427.      * scrollbar "knob" or "thumb" is proportional to the extent.
  428.      * 
  429.      * @return the value of the model's extent property
  430.      * @see #setVisibleAmount
  431.      */
  432.     public int getVisibleAmount() { 
  433.         return getModel().getExtent(); 
  434.     }
  435.  
  436.  
  437.     /**
  438.      * Set the model's extent property.
  439.      * 
  440.      * @see #getVisibleAmount
  441.      * @see BoundedRangeModel#setExtent
  442.      * @beaninfo
  443.      *   preferred: true
  444.      * description: The amount of the view that is currently visible.
  445.      */
  446.     public void setVisibleAmount(int extent) { 
  447.         getModel().setExtent(extent); 
  448.     }
  449.  
  450.  
  451.     /**
  452.      * Returns the minimum value supported by the scrollbar 
  453.      * (usually zero).
  454.      *
  455.      * @return the value of the model's minimum property
  456.      * @see #setMinimum
  457.      */
  458.     public int getMinimum() { 
  459.         return getModel().getMinimum(); 
  460.     }
  461.  
  462.  
  463.     /**
  464.      * Sets the model's minimum property.
  465.      *
  466.      * @see #getMinimum
  467.      * @see BoundedRangeModel#setMinimum
  468.      * @beaninfo
  469.      *   preferred: true
  470.      * description: The scrollbar's minimum value.
  471.      */
  472.     public void setMinimum(int minimum) { 
  473.         getModel().setMinimum(minimum); 
  474.     }
  475.  
  476.  
  477.     /**
  478.      * The maximum value of the scrollbar is maximum - extent.
  479.      *
  480.      * @return the value of the model's maximum property
  481.      * @see #setMaximum
  482.      */
  483.     public int getMaximum() { 
  484.         return getModel().getMaximum(); 
  485.     }
  486.  
  487.  
  488.     /**
  489.      * Sets the model's maximum property.  Note that the scrollbar's value
  490.      * can only be set to maximum - extent.
  491.      * 
  492.      * @see #getMaximum
  493.      * @see BoundedRangeModel#setMaximum
  494.      * @beaninfo
  495.      *   preferred: true
  496.      * description: The scrollbar's maximum value. 
  497.      */
  498.     public void setMaximum(int maximum) { 
  499.         getModel().setMaximum(maximum); 
  500.     }
  501.  
  502.  
  503.     /**
  504.      * True if the scrollbar knob is being dragged.
  505.      * 
  506.      * @return the value of the model's valueIsAdjusting property
  507.      * @see #setValueIsAdjusting
  508.      */
  509.     public boolean getValueIsAdjusting() { 
  510.         return getModel().getValueIsAdjusting(); 
  511.     }
  512.  
  513.  
  514.     /**
  515.      * Sets the model's valueIsAdjusting property.  Scrollbar look and
  516.      * feel implementations should set this property to true when 
  517.      * a knob drag begins, and to false when the drag ends.  The
  518.      * scrollbar model will not generate ChangeEvents while
  519.      * valueIsAdjusting is true.
  520.      * 
  521.      * @see #getValueIsAdjusting
  522.      * @see BoundedRangeModel#setValueIsAdjusting
  523.      * @beaninfo
  524.      *      expert: true
  525.      *       bound: true
  526.      * description: True if the scrollbar thumb is being dragged.
  527.      */
  528.     public void setValueIsAdjusting(boolean b) { 
  529.         BoundedRangeModel m = getModel();   
  530.         boolean oldValue = m.getValueIsAdjusting();
  531.         m.setValueIsAdjusting(b);
  532.    
  533.         if ((oldValue != b) && (accessibleContext != null)) {
  534.             accessibleContext.firePropertyChange(
  535.                     AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
  536.                     ((oldValue) ? AccessibleState.BUSY : null),
  537.                     ((b) ? AccessibleState.BUSY : null));
  538.         }
  539.     }
  540.  
  541.  
  542.     /**
  543.      * Sets the four BoundedRangeModel properties after forcing
  544.      * the arguments to obey the usual constraints:
  545.      * <pre>
  546.      * minimum <= value <= value+extent <= maximum
  547.      * </pre>
  548.      * <p>
  549.      * 
  550.      * @see BoundedRangeModel#setRangeProperties
  551.      * @see #setValue
  552.      * @see #setVisibleAmount
  553.      * @see #setMinimum
  554.      * @see #setMaximum
  555.      */
  556.     public void setValues(int newValue, int newExtent, int newMin, int newMax)    
  557.     {
  558.         BoundedRangeModel m = getModel();
  559.         int oldValue = m.getValue();
  560.         m.setRangeProperties(newValue, newExtent, newMin, newMax, m.getValueIsAdjusting());
  561.  
  562.         if (accessibleContext != null) {
  563.             accessibleContext.firePropertyChange(
  564.                     AccessibleContext.ACCESSIBLE_VALUE_PROPERTY,
  565.                     new Integer(oldValue),
  566.                     new Integer(m.getValue()));
  567.         }
  568.     }
  569.  
  570.  
  571.     /**
  572.      * Adds an AdjustmentListener.  Adjustment listeners are notified
  573.      * each time the scrollbar's model changes.  Adjustment events are 
  574.      * provided for backwards compatability with java.awt.Scrollbar.
  575.      * <p>
  576.      * Note that the AdjustmentEvents type property will always have a
  577.      * placeholder value of AdjustmentEvent.TRACK because all changes
  578.      * to a BoundedRangeModels value are considered equivalent.  To change
  579.      * the value of a BoundedRangeModel one just sets its value property,
  580.      * i.e. model.setValue(123).  No information about the origin of the
  581.      * change, e.g. it's a block decrement, is provided.  We don't try
  582.      * fabricate the origin of the change here.
  583.      *
  584.      * @param l the AdjustmentLister to add
  585.      * @see #removeAdjustmentListener
  586.      * @see BoundedRangeModel#addChangeListener
  587.      */
  588.     public void addAdjustmentListener(AdjustmentListener l)   {
  589.         listenerList.add(AdjustmentListener.class, l);
  590.     }
  591.  
  592.  
  593.     /**
  594.      * Removes an AdjustmentEvent listener.
  595.      *
  596.      * @param l the AdjustmentLister to remove
  597.      * @see #addAdjustmentListener
  598.      */
  599.     public void removeAdjustmentListener(AdjustmentListener l)  {
  600.         listenerList.remove(AdjustmentListener.class, l);
  601.     }
  602.  
  603.  
  604.     /*
  605.      * Notify listeners that the scrollbar's model has changed.
  606.      * 
  607.      * @see #addAdjustmentListener
  608.      * @see EventListenerList
  609.      */
  610.     protected void fireAdjustmentValueChanged(int id, int type, int value) {
  611.         Object[] listeners = listenerList.getListenerList();
  612.         AdjustmentEvent e = null;
  613.         for (int i = listeners.length - 2; i >= 0; i -= 2) {
  614.             if (listeners[i]==AdjustmentListener.class) {
  615.                 if (e == null) {
  616.                     e = new AdjustmentEvent(this, id, type, value);
  617.                 }
  618.                 ((AdjustmentListener)listeners[i+1]).adjustmentValueChanged(e);
  619.             }          
  620.         }
  621.     }   
  622.  
  623.  
  624.     /** 
  625.      * This class listens to ChangeEvents on the model and forwards 
  626.      * AdjustmentEvents for the sake of backwards compatibility. 
  627.      * Unfortunately there's no way to determine the proper
  628.      * type of the AdjustmentEvent as all updates to the model's
  629.      * value are considered equivalent. 
  630.      */
  631.     private class ModelListener implements ChangeListener, Serializable {
  632.         public void stateChanged(ChangeEvent e)   {
  633.             int id = AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED;
  634.             int type = AdjustmentEvent.TRACK;
  635.             fireAdjustmentValueChanged(id, type, getValue());
  636.         }
  637.     }
  638.  
  639.     // PENDING(hmuller) - the next three methods should be removed
  640.  
  641.     /**
  642.      * The scrollbar is flexible along it's scrolling axis and 
  643.      * rigid along the other axis.
  644.      */
  645.     public Dimension getMinimumSize() {
  646.         Dimension pref = getPreferredSize();
  647.         if (orientation == VERTICAL) {
  648.             return new Dimension(pref.width, 5);
  649.         } else {
  650.             return new Dimension(5, pref.height);
  651.         }
  652.     }
  653.  
  654.     /**
  655.      * The scrollbar is flexible along it's scrolling axis and
  656.      * rigid along the other axis.
  657.      */
  658.     public Dimension getMaximumSize() {
  659.         Dimension pref = getPreferredSize();
  660.         if (getOrientation() == VERTICAL) {
  661.             return new Dimension(pref.width, Short.MAX_VALUE);
  662.         } else {
  663.             return new Dimension(Short.MAX_VALUE, pref.height);
  664.         }
  665.     }
  666.  
  667.     /**
  668.      * Enables the component so that the knob position can be changed.
  669.      * When the disabled, the knob position cannot be changed.
  670.      *
  671.      * @param b a boolean value, where true enables the component and
  672.      *          false disables it
  673.      */
  674.     public void setEnabled(boolean x)  {
  675.         super.setEnabled(x);
  676.         Component[] children = getComponents();
  677.         for(int i = 0; i < children.length; i++) {
  678.             children[i].setEnabled(x);
  679.         }
  680.     }
  681.  
  682.  
  683. /////////////////
  684. // Accessibility support
  685. ////////////////
  686.  
  687.     /**
  688.      * Get the AccessibleContext associated with this JComponent
  689.      *
  690.      * @return the AccessibleContext of this JComponent
  691.      */
  692.     public AccessibleContext getAccessibleContext() {
  693.         if (accessibleContext == null) {
  694.             accessibleContext = new AccessibleJScrollBar();
  695.         }
  696.         return accessibleContext;
  697.     }
  698.  
  699.     /**
  700.      * The class used to obtain the accessible role for this object.
  701.      * <p>
  702.      * Warning: serialized objects of this class will not be compatible with
  703.      * future swing releases.  The current serialization support is appropriate
  704.      * for short term storage or RMI between Swing1.0 applications.  It will
  705.      * not be possible to load serialized Swing1.0 objects with future releases
  706.      * of Swing.  The JDK1.2 release of Swing will be the compatibility
  707.      * baseline for the serialized form of Swing objects.
  708.      */
  709.     protected class AccessibleJScrollBar extends AccessibleJComponent
  710.         implements AccessibleValue {
  711.  
  712.         /**
  713.          * Get the state set of this object.
  714.          *
  715.          * @return an instance of AccessibleState containing the current state 
  716.          * of the object
  717.          * @see AccessibleState
  718.          */
  719.         public AccessibleStateSet getAccessibleStateSet() {
  720.             AccessibleStateSet states = super.getAccessibleStateSet();
  721.             if (getValueIsAdjusting()) {
  722.                 states.add(AccessibleState.BUSY);
  723.             }
  724.             if (getOrientation() == VERTICAL) {
  725.                 states.add(AccessibleState.VERTICAL);
  726.             } else {
  727.                 states.add(AccessibleState.HORIZONTAL);
  728.             }
  729.             return states;
  730.         }
  731.  
  732.         /**
  733.          * Get the role of this object.
  734.          *
  735.          * @return an instance of AccessibleRole describing the role of the 
  736.          * object
  737.          */
  738.         public AccessibleRole getAccessibleRole() {
  739.             return AccessibleRole.SCROLL_BAR;
  740.         }
  741.  
  742.         /**
  743.          * Get the AccessibleValue associated with this object if one
  744.          * exists.  Otherwise return null.
  745.          */
  746.         public AccessibleValue getAccessibleValue() {
  747.             return this;
  748.         }
  749.  
  750.         /**
  751.          * Get the accessible value of this object.
  752.          *
  753.          * @return The current value of this object.
  754.          */
  755.         public Number getCurrentAccessibleValue() {
  756.             return new Integer(getValue());
  757.         }
  758.  
  759.         /**
  760.          * Set the value of this object as a Number.
  761.          *
  762.          * @return True if the value was set.
  763.          */
  764.         public boolean setCurrentAccessibleValue(Number n) {
  765.             if (n instanceof Integer) {
  766.                 setValue(n.intValue());
  767.                 return true;
  768.             } else {
  769.                 return false;
  770.             }
  771.         }
  772.  
  773.         /**
  774.          * Get the minimum accessible value of this object.
  775.          *
  776.          * @return The minimum value of this object.
  777.          */
  778.         public Number getMinimumAccessibleValue() {
  779.             return new Integer(getMinimum());
  780.         }
  781.  
  782.         /**
  783.          * Get the maximum accessible value of this object.
  784.          *
  785.          * @return The maximum value of this object.
  786.          */
  787.         public Number getMaximumAccessibleValue() {
  788.             return new Integer(getMaximum());
  789.         }
  790.  
  791.     } // AccessibleJScrollBar
  792. }
  793.